package cn.net.autocode.platform.constants;

import cn.net.autocode.core.utils.UserThreadLocalUtils;

import java.util.Date;

public class PlatformConstant {

    /** 登录用户Token令牌缓存KEY前缀 */
    public static final String PREFIX_USER_TOKEN  = "platform:token:";


    /** 移动登录用户Token令牌缓存KEY前缀 */
    public static final String M_PREFIX_USER_TOKEN  = "platform:mtoken:";


    /** 默认页面地址 */

    public static final String MAIN_PATH = "/platform/main";

    public static final String FORLOGIN_PATH = "/platform/forLogin";

    public static final String LOGIN_VIEW = "/platform/login";

    public static String strValue(String flagValue){
        String lowFlag = flagValue.trim().toLowerCase();
        return switch (lowFlag) {
            case "@myusername" -> UserThreadLocalUtils.getUserName();
            case "@myfullname" -> UserThreadLocalUtils.getRealName();
            case "@myorgan" -> UserThreadLocalUtils.getOrgCode();
            default -> flagValue.trim();
        };
    }

    public static Date dateValue(String flagValue){
        String lowFlag = flagValue.trim().toLowerCase();
        if("@now".equals(lowFlag)){
            return new Date();
        }else if("@now()".equals(lowFlag)){
            return new Date();
        }else{
            return null;
        }
    }
}
